package com.qezhhnjy.mall.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.product.Category;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.product.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "商品三级分类接口")
@Slf4j
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取商品三级分类信息")
    public BaseResult<Category> get(Long id) {
        Category category = categoryService.getById(id);
        return BaseResult.success(category);
    }

    @PostMapping("/save")
    @Operation(summary = "新增商品三级分类信息")
    public BaseResult<Category> save(@RequestBody Category category) {
        categoryService.save(category);
        return BaseResult.success(category);
    }

    @PutMapping("/update")
    @Operation(summary = "更新商品三级分类信息")
    public BaseResult<Category> update(@RequestBody Category category) {
        categoryService.updateById(category);
        return BaseResult.success(category);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取商品三级分类信息")
    public BaseResult<Page<Category>> page(@RequestBody Page<Category> page) {
        categoryService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除商品三级分类信息")
    public BaseResult<Long> delete(Long id) {
        categoryService.removeById(id);
        return BaseResult.success(id);
    }
}

